package com.jy.rhin.facade.controller.document;

import com.jy.framework.base.entity.Page;
import com.jy.framework.base.entity.Result;
import com.jy.rhin.application.document.DocumentBizService;
import com.jy.rhin.facade.dto.DocumentDetailDto;
import com.jy.rhin.facade.dto.DocumentManagerDTO;
import com.jy.rhin.facade.dto.TemplateRespDto;
import com.jy.rhin.sdk.dto.document.cda.ClinicalDocumentData;
import com.jy.rhin.sdk.dto.document.query.DocumentManagerReqDto;
import com.jy.rhin.sdk.dto.document.query.DocumentManagerRespDto;
import com.jy.rhin.sdk.dto.document.query.GetContentDto;
import com.jy.rhin.sdk.dto.document.query.GetContentReqDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author dhl
 * @date 2022/5/25
 * @Description
 */
@RestController
@RequestMapping("/document")
@Api(tags = "文档共享")
@Slf4j
public class DocumentBizController {

    @Resource
    DocumentBizService documentBizService;

    @ApiOperation("分页查询文档列表")
    @GetMapping("/queryPage")
    public Result<Page<DocumentManagerDTO>> queryPage(DocumentManagerReqDto dto) {
        Page<DocumentManagerDTO> pageResult = documentBizService.queryPage(dto);
        return Result.success(pageResult);
    }

    @ApiOperation("查询文档详情")
    @GetMapping("/queryDetail")
    public Result<DocumentDetailDto> queryDetail(GetContentDto dto) {
        DocumentDetailDto detailDto = documentBizService.queryDetail(dto);
        return Result.success(detailDto);
    }

    @ApiOperation("下载xml")
    @GetMapping("/downloadXml")
    public void downloadXml(HttpServletResponse response, GetContentDto dto) {
        documentBizService.downloadXml(response, dto);
    }

    @ApiOperation("批量下载xml")
    @PostMapping("/batchDownloadXml")
    public void batchDownloadXml(HttpServletResponse response, @RequestBody GetContentReqDto dto) {
        documentBizService.batchDownloadXml(response, dto);
    }
    
    @ApiOperation("文档提交注册接口")
    @PostMapping("/register")
    public void register( @RequestBody ClinicalDocumentData data) {
        documentBizService.register(data);
    }


    @ApiOperation("初始化文档说明模板")
    @GetMapping("/initTemplate")
    public Result initTemplate(@RequestBody TemplateRespDto t) {
        documentBizService.initTemplate(t.getValue(),t.getType());
        return Result.success();
    }
}